package cn.wuyu.baselibrary.widget;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.wang.avi.AVLoadingIndicatorView;
import com.wang.avi.indicators.LineScalePulseOutIndicator;

import cn.wuyu.baselibrary.R;
import cn.wuyu.baselibrary.utils.ResUtils;


/**
 * Created by xuzongmeng on 2016/10/28.
 * X
 */

public class LoadingView {
	public BounceLoadingView bounceloadingview;
	private String hintText;
	private View view;
	private AVLoadingIndicatorView avLoadingIndicatorView;
	
	public LoadingView(Context context, String hintText) {
		this.hintText = hintText;
		initView(context);
	}
	
	private void initView(Context context) {
		view = LayoutInflater.from(context).inflate(R.layout.view_loading_page, null);
		TextView textView = view.findViewById(R.id.loading_text);
		avLoadingIndicatorView = view.findViewById(R.id.AVLoadingIndicatorView);
//        avLoadingIndicatorView.setIndicator(new LineScaleIndicator());
//        avLoadingIndicatorView.setIndicator(new LineScalePartyIndicator());
		avLoadingIndicatorView.setIndicator(new LineScalePulseOutIndicator());
//		avLoadingIndicatorView.setIndicatorColor(ResUtils.getAttrColor(R.attr.theme_col));
		if (!TextUtils.isEmpty(hintText)) {
			textView.setText(hintText);
		}
		bounceloadingview = view.findViewById(R.id.bounceloadingview);
		bounceloadingview.addBitmap(R.mipmap.loading_bidding);
		bounceloadingview.addBitmap(R.mipmap.loading_business_center);
		bounceloadingview.addBitmap(R.mipmap.loading_create);
//		int appBlackTheme = R.style.AppBlackTheme;
		/*SettingConfig.isDarkMode()?*/
		bounceloadingview.setShadowColor(ResUtils.getAttrColor(R.attr.theme_col));
		bounceloadingview.setDuration(800);
		bounceloadingview.start();
	}
	
	public View getLoadingView() {
		return view;
	}
	
	public void startAnim() {
		if (avLoadingIndicatorView != null) {
			avLoadingIndicatorView.show();
		}
	}
	
	public void stopAnim() {
		if (avLoadingIndicatorView != null) {
			avLoadingIndicatorView.hide();
		}
	}
}
